﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;

namespace PlanoAulaHelper.Reports
{
    public partial class relPlanoAulaForm : System.Windows.Forms.FormEdicao
    {
        public relPlanoAulaForm(int IdItem ) :base(IdItem)
        {
            InitializeComponent();
        }

        private void relPlanoAulaCompletoForm_Load(object sender, EventArgs e)
        {
            AtualizarRelatorio();
            this.rptPlanoAula.RefreshReport();
        }

        private void AtualizarRelatorio()
        {
            string Universidade, Semestre, Professor, Materia, Curso, CargaHoraria, Ano;
            using (dbContext db = new dbContext())
            {
                var planoAula = (from p in db.PlanoAulaCabs
                                 where p.Id == IdItem
                                 select p).Single();

                Universidade = planoAula.Universidade;
                Ano = planoAula.Ano.ToString();
                Semestre = planoAula.Semestre.ToString();
                Professor = planoAula.Professor;
                Curso = planoAula.Curso;
                CargaHoraria = planoAula.CargaHoraria.ToString();
                Materia = planoAula.Materia;

            }
            Relatorios.Clear();
            Relatorios.RelatorioPlanoAula.Merge(Reports.Relatorios.ObterRelatorioAvaliacao(IdItem));
            Relatorios.Avaliacao.Merge(Reports.Relatorios.ObterAvaliacoes(IdItem));
            Relatorios.AcceptChanges();

            rptPlanoAula.LocalReport.DisplayName = string.Format("P.A. {0}.{1} - {2}", Ano, Semestre, Materia);
            rptPlanoAula.LocalReport.SetParameters(new ReportParameter[] {
                    new ReportParameter("Universidade", Universidade, false),
                    new ReportParameter("Semestre", Semestre, false),
                    new ReportParameter("Professor", Professor, false),
                    new ReportParameter("Disciplina", Materia, false),
                    new ReportParameter("Curso", Curso, false),
                    new ReportParameter("CargaHoraria", CargaHoraria, false),
                    new ReportParameter("Ano", Ano)
                });
        }

        private void rptPlanoAula_ReportRefresh(object sender, CancelEventArgs e)
        {
            AtualizarRelatorio();

        }
    }
}
